package cn.edu.neusoft.yuejian.frgment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import java.util.List;

import cn.edu.neusoft.yuejian.R;
import cn.edu.neusoft.yuejian.adapter.hdadapter;
import cn.edu.neusoft.yuejian.bean.activity;
import cn.edu.neusoft.yuejian.model.yuemodel;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * A simple {@link Fragment} subclass.
 */
public class HdFragment extends Fragment {
    private View view = null;
    private RecyclerView recyclerView;
    public HdFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view= inflater.inflate(R.layout.fragment_hd, container, false);
        initViews();
        initEvents();
        initData();
        return view;
    }
    private void initViews() {
        recyclerView=(RecyclerView)view.findViewById(R.id.rv_sy);

    }
    private void initEvents() {

    }

    private void initData() {
        yuemodel yuemodel=new yuemodel();
        Call<List<activity>> call=yuemodel.getactivitylist();
        call.enqueue(new Callback<List<activity>>() {
            @Override
            public void onResponse(Call<List<activity>> call, Response<List<activity>> response) {
                List<activity> data= response.body();
                hdadapter adpter = new hdadapter(getActivity(), data);
                LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
                linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                recyclerView.setLayoutManager(linearLayoutManager);
                recyclerView.setAdapter(adpter);
                recyclerView.setItemAnimator(new DefaultItemAnimator());
            }

            @Override
            public void onFailure(Call<List<activity>> call, Throwable t) {
                Toast.makeText(getActivity(), "获取列表失败", Toast.LENGTH_SHORT);
            }
        });

    }



}
